--- title: "1046. Last Stone Weight" created: 2025-12-18 --- # 1046. Last Stone Weight ## 题目 [**1046. Last Stone Weight**](https://leetcode.com/problems/last-stone-weight/) ![[image-c497fc5d.png]] ## 思路分析 ![[image-89f8327b.png]] 优先队列实现 ## 代码实现 ```java class Solution { public int lastStoneWeight(int[] stones) { PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); for(int stone:stones){ pq.offer(stone); } while(pq.size()>1){ int x = pq.poll(); int y = pq.poll(); if(x>y){ pq.offer(x-y); } } return pq.isEmpty() ? 0 : pq.peek(); } } ``` ## 同类题型 ## 视频讲解